﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WorkflowManagement.Web.UI
{
    /// <summary>
    /// This class acts as a proxy for <see cref="WorkflowManager"/>. The <see cref="WorkflowManagerProxy">proxy</see> can be 
    /// used inn user controls and web content pages where the main <see cref="WorkflowManager"/> is inaccessible.
    /// </summary>
    public class WorkflowManagerProxy: WorkflowManagerBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="WorkflowManagerProxy"/> class.
        /// </summary>
        public WorkflowManagerProxy()
        {
        }

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            
            if (!DesignMode)
            {            
                WorkflowManager manager = WorkflowManager.GetCurrentWorkflowManager(Page);
                manager.RegisterProxy(this);           
            }
        }

        internal override void ExecuteWorkflow(Type workflowType, Dictionary<string, object> parameters)
        {
            if (!DesignMode)
                WorkflowManager.GetCurrentWorkflowManager(Page).ExecuteWorkflow(workflowType, parameters);
        }
    }
}
